/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package gui2;

import Technical.GridReader;
import java.awt.BorderLayout;
import java.awt.TextField;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;

/**
 *
 * @author Ljungend
 */
public class ChooseBotDifficulty extends JDialog{
    
    public int player1Type = 2;
    public int player2Type = 2;
    public int aI1Level = 1;
    public int aI2Level = 1;
    public int debugmode = 0;
    public int trainingMode = 0;
    public JButton btnOk;
    public boolean doOnce = true;
    public TextField textField = new TextField(20);
    public JCheckBox debug = new JCheckBox("Debug mode");
    public JCheckBox training = new JCheckBox("Training mode");
    private int[][] grid = new int[8][8];
    
     public ChooseBotDifficulty(int width, int height) {
            this.setSize(width, height);
            this.setTitle("Choose Bot Difficulty");
            this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
            this.setLocation(400, 200);
            this.setResizable(false);
            InitComponents();
            this.show();        
    }
    
    private void InitComponents(){
        textField.setText("standard.txt");
        btnOk = new JButton("ok");
        JLabel lblPLayer1 = new JLabel("Player 1: ");
        JLabel lblPLayer2 = new JLabel("Player 2: ");        
        JRadioButton cbAI1 = new JRadioButton("AI");
        JRadioButton player1 = new JRadioButton("Human");
        JRadioButton easy1 = new JRadioButton("Easy");
        JRadioButton medium1 = new JRadioButton("Medium");
        JRadioButton hard1 = new JRadioButton("Hard");
        JRadioButton cbAI2 = new JRadioButton("AI");
        JRadioButton player2 = new JRadioButton("Human");
        JRadioButton easy2 = new JRadioButton("Easy");
        JRadioButton medium2 = new JRadioButton("Medium");
        JRadioButton hard2 = new JRadioButton("Hard");        
        JPanel panelNorth = new JPanel();
        JPanel panelCenter = new JPanel();
        JPanel panelSouth = new JPanel();
        ButtonGroup bgPlayer1 = new ButtonGroup();
        ButtonGroup bgPlayer2 = new ButtonGroup();
        ButtonGroup bgAI1Level = new ButtonGroup();
        ButtonGroup bgAI2Level = new ButtonGroup();
                        
        debug.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                debugmode = 1;
            }
        });
        
        training.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                trainingMode = 1;
            }
        });
                
        player1.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent ae) {
                player1Type = 1;
            }
        });
        
        cbAI1.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent ae) {
                player1Type = 2;
            }
        });
        
        player2.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent ae) {
                player2Type = 1;
            }
        });
        
        cbAI2.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent ae) {
                player2Type = 2;
            }
        });
        
        easy1.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent ae) {
                aI1Level = 1;
            }
        });
        
        medium1.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent ae) {
                aI1Level = 2;
            }
        });
        
        hard1.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent ae) {
                aI1Level = 3;
            }
        });
        
        easy2.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent ae) {
                aI2Level = 1;
            }
        });
        
        medium2.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent ae) {
                aI2Level = 2;
            }
        });
        
        hard2.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent ae) {
                aI2Level = 3;
            }
        });
        
        bgPlayer1.add(cbAI1);
        bgPlayer1.add(player1);
        bgPlayer2.add(cbAI2);
        bgPlayer2.add(player2);
        bgAI1Level.add(easy1);
        bgAI1Level.add(medium1);
        bgAI1Level.add(hard1);
        bgAI2Level.add(easy2);
        bgAI2Level.add(medium2);
        bgAI2Level.add(hard2);
        
        panelNorth.add(lblPLayer1);        
        panelNorth.add(player1);
        panelNorth.add(cbAI1);
        panelNorth.add(easy1);
        panelNorth.add(medium1);
        panelNorth.add(hard1);
        
        panelCenter.add(lblPLayer2);        
        panelCenter.add(player2);
        panelCenter.add(cbAI2);
        panelCenter.add(easy2);
        panelCenter.add(medium2);
        panelCenter.add(hard2);
        
        panelSouth.add(btnOk);
        panelSouth.add(debug);
        panelSouth.add(training);
        panelSouth.add(textField);
        
        this.add(panelNorth, BorderLayout.NORTH);
        this.add(panelCenter, BorderLayout.CENTER);
        this.add(panelSouth, BorderLayout.SOUTH);
        
        cbAI1.setSelected(true);
        cbAI2.setSelected(true);
        //player1.setSelected(true);
        //player2.setSelected(true);
        easy1.setSelected(true);
        easy2.setSelected(true);
    }

    public int getPlayer1Type() {
        return player1Type;
    }

    public int getPlayer2Type() {
        return player2Type;
    }

    public int getaI1Level() {
        return aI1Level;
    }

    public int getaI2Level() {
        return aI2Level;
    }

    public int getDebugmode() {
        return debugmode;
    }

    public int getTrainingMode() {
        return trainingMode;
    }
    
    public int[][] getGrid()
    {
        GridReader gr = new GridReader();
        grid = gr.ReadGrid(textField.getText());
        
        return grid;
    }
}
